<!DOCTYPE html>
<html lang="zh">

<head>
	<th:block th:include="include :: header('故障分析报告')" />
	<th:block th:include="include :: layout-latest-css" />
	<th:block th:include="include :: ztree-css" />
</head>

<body class="gray-bg">
	<div class="ui-layout-center">
		<div class="container-div">
			<div class="row">
				<div class="col-sm-12 search-collapse">
					<form id="user-form">
						<!-- <input type="hidden" id="sceneId" name="sceneId">
						<input type="hidden" id="parentId" name="parentId"> -->
						<!-- <div class="select-list">
							<ul>
								<li style="display: flex;">
									<label>故障名称:</label>
									<input type="text" name="recordName" placeholder="请输入故障名称" />
								</li>
								<li style="display: flex;">
									<label>场景名称:</label>
									<input type="text" name="ejname" placeholder="请输入场景名称" />
								</li>
								<li>
									时间：
									<input type="date"  name="createTime" class="layui-input startTime"/>
								</li>
								<li>
									<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
											class="fa fa-search"></i>&nbsp;搜索</a>
									<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
											class="fa fa-refresh"></i>&nbsp;重置</a>
								</li>
							</ul>
						</div> -->
						<div class="select-list">
							<ul>
								<li style="display: flex;">
									<label style="margin-right: 10px;width: 80px;">请选择机构:</label>
									<input type="hidden" name="azqyname" id="azqyname">
									<select  id="dev_azdw1_select1"
										class="first form-control azdw-select1" data-index="1"
										style="width: 95px;">
									</select>
								</li>
								<li>
									<select name="ejdw_id" id="dev_azdw2_select1"
										class="second form-control azdw-select1" data-index="2"
										style="width: 95px;"></select>
								</li>
								<li>
									<select name="dw_3_id" id="dev_azdw3_select1"
										class="third form-control azdw-select1" data-index="3"
										style="width: 95px;"></select>
								</li>
								<li>
									<select name="dw_4_id" id="dev_azdw4_select1"
										class="fourth form-control azdw-select1" data-index="4"
										style="width: 95px;"></select>
								</li>
								<li>
									<select name="dw_5_id" id="dev_azdw5_select1"
										class="fifth form-control azdw-select1" data-index="5"
										style="width: 95px;"></select>
								</li>
								<!-- <li style="display: flex;">
									<label>设备名称:</label>
									<select name="equipmentId" id="point-select1" style="width:150px"
										class="form-control"></select>
								</li> -->
								<li style="display: flex;">
									<label>故障名称:</label>
									<input type="text" name="recordname" placeholder="请输入故障名称" />
								</li>
								<li>
									开始时间：
									<input type="date"  name="reostartTime" class="layui-input startTime"/>
								</li>
								<li>
									结束时间：
									<input type="date"  name="reoendTime" class="layui-input startTime"/>
								</li>
								<li>
									<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
											class="fa fa-search"></i>&nbsp;搜索</a>
									<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
											class="fa fa-refresh"></i>&nbsp;重置</a>
								</li>
							</ul>
						</div>
					</form>
				</div>

				<div class="col-sm-12 select-table table-striped">
					<table id="bootstrap-table"></table>
				</div>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: layout-latest-js" />
	<th:block th:include="include :: ztree-js" />
	<script th:inline="javascript">
		$(function () {
			var panehHidden = false;
			if ($(this).width() < 769) {
				panehHidden = true;
			}
			$('body').layout({ initClosed: panehHidden, west__size: 185 });
			// 回到顶部绑定
			if ($.fn.toTop !== undefined) {
				var opt = {
					win: $('.ui-layout-center'),
					doc: $('.ui-layout-center')
				};
				$('#scroll-up').toTop(opt);
			}
			queryUserList();

			initAZDWselect1()
			$('.azdw-select1').change(function (e) {
				var getSelectIndex = $(this).attr("data-index") || 1;
				var maxSelectIndex = 6;
				var nextSelectIndex = Number(getSelectIndex) + 1;
				let startIndex = getSelectIndex;
				while (startIndex < maxSelectIndex) {
					startIndex++;
					$(`#dev_azdw${startIndex}_select1`).val("").text("请选择")
					$("#azqyname").val($('#dev_azdw1_select1').find("option:selected").text())
					$('#equipmentId').val($(this).val())
				}
				// 获取下一级select 下拉框的数据，只有存在下一级的时候，在需要调用设置 option 方法
				if (nextSelectIndex < maxSelectIndex) {
					initAZDWselect1(nextSelectIndex);
				}
				// 调用根据条件筛选监测点
				queryPointSelect1();
			})
		});

		function queryUserList() {
			var options = {
				url: '/youtian/record/miinlist',
				method: 'GET',
				// sortName: "createTime",
				columns: [{
					checkbox: true
				},
				{
					field: 'recordname',
					title: '故障名称',
					align:'center',
				},
				{
					field: 'ejname',
					title: '组织机构',
					align:'center',
					formatter:function(value, row, index){
						return ejname = row.ejdw_name + '-' + row.dw_3_name + '-' + row.dw_4_name + '-' + row.dw_5_name + '-' + row.fdwdm_name
					}
				},
				{
					field: 'template_name',
					title: '模型名称',
					align:'center',
				},
				// {
				// 	field: 'dev_name',
				// 	title: '设备名称',
				// },
				// {
				// 	field: 'acquisition',
				// 	title: '当前采集值'
				// },


				{
					field: 'createtime',
					title: '检测日期',
					align:'center',
					
				},
				{
					title: '操作',
					align: 'center',
					formatter: function (value, row, index) {
						// if (row.userId != 1) {
						var actions = [];
						actions.push(`<a class="btn btn-success btn-xs" href="javascript:;" onclick="errDetail('${row.recordid},${row.recordname},${row.createtime},${row.ejdw_name},${row.dw_3_name},${row.dw_4_name},${row.dw_5_name},${row.fdwdm_name}')"><i class="fa fa-gear"></i>故障详情</a>`)
						// actions.push(`<a class="btn btn-success btn-xs menuItem" href="javascript:;" ><i class="fa fa-gear"></i>故障详情</a>`)
						return actions.join('');
					}
				}]
			};
			$.table.init(options);
		}

		//跳故障详情
		function errDetail(row) {
			var rowJson = row.split(',');
			let [recordId,recordName,createBy,ejdw_name,dw_3_name,dw_4_name,dw_5_name,fdwdm_name] = row.split(',');
			let url = `/page-route/fault-analysis-table?recordId=${recordId}&recordName=${recordName}&createBy=${createBy}&ejdw_name=${ejdw_name}&dw_3_name=${dw_3_name}&dw_4_name=${dw_4_name}&dw_5_name=${dw_5_name}&fdwdm_name=${fdwdm_name}`
			// console.log(rowJson);
			// console.log(menuItem);
			// window.location.href = `/page-route/fault-analysis-table?recordId=${rowJson[0]}&recordName=${rowJson[1]}&createBy=${rowJson[2]}&ejdw_name=${rowJson[3]}&dw_3_name=${rowJson[4]}&dw_4_name=${rowJson[5]}&dw_5_name=${rowJson[6]}&fdwdm_name=${rowJson[7]}`
			//  在右侧以标签的形式打开
			createMenuItem(url,'故障详情')
		}

		function initAZDWselect1(nextSelectIndex) {
			var params = {
				"jb": 1
			}
			nextSelectIndex = nextSelectIndex ? nextSelectIndex : 1;
			var $nextSelect = $(`#dev_azdw${nextSelectIndex}_select1`);
			if (nextSelectIndex > 1) {
				params = {
					fdwdm: $(`#dev_azdw${nextSelectIndex - 1}_select1`).val()
				}
			}
			$.ajax({
				type: "post",
				url: "/gzmx_scdw/gzmx_scdw/list",
				data: params,
				success: function (res) {
					var optionHTML = `<option value="">请选择</option>`
					for (let i = 0; i < res.length; i++) {
						optionHTML += `<option value="` + res[i].id + `">` + res[i].dwmc + `</option>`
					}
					$nextSelect.html(optionHTML);
				},
				error: function (error) {
					$.modal.alertWarning(error);
				}
			});
		}

		function queryPointSelect1() {
			$("#point-select1").html(`<option value="">请选择</option>`);
			let data = {
				dw_5_id: $("#dev_azdw5_select1").val()
			};
			console.log(data, "data");
			$.ajax({
				method: "POST",
				url: "/gzmx_tag/gzmx_tag/dev_name",
				contentType: "application/json",
				dataType: 'json',
				data: JSON.stringify(data),
				success: function (res) {
					var optionHTML = `<option value="">请选择</option>`;
					for (let i = 0; i < res.data.length; i++) {
						var item = res.data[i];
						optionHTML += `<option value="${item.id}"  >${item.dev_name}</option>`
					}
					$("#point-select1").html(optionHTML);
					$("#upperLimit").val("")
					$("#lowerLimit").val("")
				}
			});
		}
	</script>
</body>

</html>